/**
 * 
 * @param {}
 *            s
 * @return {Boolean}
 */
String.prototype.endWith = function(s) {
	if (s == null || s == "" || this.length == 0 || s.length > this.length)
		return false;
	if (this.substring(this.length - s.length) == s)
		return true;
	else
		return false;
	return true;
}
/**
 * 
 * @param {}
 *            s
 * @return {Boolean}
 */
String.prototype.startWith = function(s) {
	if (s == null || s == "" || this.length == 0 || s.length > this.length)
		return false;
	if (this.substr(0, s.length) == s)
		return true;
	else
		return false;
	return true;
}
/**
 * 
 * @param {}
 *            s
 * @return {Boolean}
 */
String.prototype.equals = function(s) {
	if (s == this)
		return true;
	else
		return false;
}
/**
 * 
 * @param {}
 *            str
 * @return {Boolean}
 */
function isBlank(str) {
	if (str == null || $.trim(str) == "") {
		return true;
	}
	return false;
}
/**
 * 
 * @param {}
 *            str
 * @return {Boolean}
 */
function isNotBlank(str) {
	return !isBlank(str);
}

/**
 * 
 * @param {}
 *            message
 * @param {}
 *            callback
 */
function showInfo(message, callback) {
	showMessage({
		message : message
	}, {
		OK : function() {
			if (callback) {
				callback();
			}
		}
	})
}
/**
 * show model window message
 * 
 * @param {}
 *            message
 */
function showMessage(options, buttons) {
	if (options.length < 1)
		return;
	var dialogWindow = null;
	if (options.object) {
		dialogWindow = options.object;
	} else {
		var level = $("<p><span>").addClass("ui-icon").addClass(
				"ui-icon-circle-check").css("float", "left").css("margin",
				"0 7px 50px 0");
		var message = $("<p>").html(options.message);
		dialogWindow = $("<div>").attr("id", "dialog-message").attr("title",
				options.title ? options.title : "Attention").css("display",
				"none").append(message);
		$("div#body").append(dialogWindow);
	}
	closeDialog = function() {
		dialogWindow.dialog("destroy");
	}

	var butts = {};
	if (buttons) {
		$.each(buttons, function(i, fun) {
			var callbacks = $.Callbacks();
			callbacks.add(closeDialog);
			callbacks.add(fun);
			fun = callbacks.fire;
			butts[i] = fun;
		})
	}
	dialogWindow.dialog({
		modal : true,
		width : options.width ? options.width : 300,
		height : options.height ? options.height : "auto",
		close : function(event, ui) {
			if (options.callback)
				options.callback();
		},
		buttons : butts
	});
}

(function($) {
	jQuery.fn.datebind = function(opts) {
		if (opts == "destroy") {
			$(this).datepicker("destroy");
		} else {
			opts = jQuery.extend({
				format : 'yy-mm-dd hh:mm',
				minDate : null,
				callback : function() {
					return false;
				}
			}, opts || {});
			/*
			 * var currentLang = navigator.language || navigator.userLanguage;
			 * if (!currentLang) currentLang = navigator.browserLanguage;
			 */
			/*
			 * var datepicker_CurrentInput;
			 * 
			 * $.datepicker.setDefaults({ closeText : 'Clear', showButtonPanel :
			 * true, beforeShow : function(input, inst) {
			 * datepicker_CurrentInput = input; } });
			 * 
			 * $(".ui-datepicker-close").on("click", function() {
			 * datepicker_CurrentInput.value = ""; });
			 */
			/*
			 * var region = $.datepicker.regional[currentLang]; if (region)
			 * $.datepicker.setDefaults(region);
			 */
			$(this).datepicker({
				changeMonth : true,
				changeYear : true,
				showButtonPanel : true,
				constrainInput : true,
				showOn : 'button',
				buttonImage : ctx + '/images/calendar.gif',
				buttonImageOnly : true,
				minDate : opts.minDate,
				showAnim : 'slideDown',
				dateFormat : opts.format,
				onClose : opts.callback
			});

		}
	}
})(jQuery);
(function($) {
	jQuery.fn.ajaxSubmit2 = function(options) {
		options = jQuery.extend({
			url : $(this).attr("action"),
			type : 'POST',
			data : {},
			dataType : 'html',
			success : function() {
				return false;
			},
			error : function() {
			},
			complete : function() {
			}
		}, options || {});
		var dataArray = $(this).serializeArray();
		var data = {};
		for (d in dataArray) {
			data[dataArray[d].name] = dataArray[d].value;
		}
		if (options.data) {
			data = $.extend({}, data, options.data);
		}
		$.ajax({
			type : options.type,
			url : options.url,
			data : data,
			dataType : options.dataType,
			success : options.success,
			error : options.error,
			complete : options.complete
		})

	}
})(jQuery);
debug = true;
// helper for console logging
function log(msg) {
	if (!debug)
		return;
	msg == undefined ? '[jquery.form] '
			+ Array.prototype.join.call(arguments, '') : msg;
	if (window.console && window.console.log) {
		window.console.log(msg);
	} else if (window.opera && window.opera.postError) {
		window.opera.postError(msg);
	}
};

// 你需要获取值的js文件名
function getScriptArgs(fileName) {
	// 获取到所有<script>对象
	var scripts = document.getElementsByTagName("script");
	var resultJson = {};
	for ( var i = 0; i < scripts.length; i++) {
		var src = scripts[i].src;
		// 取得你想要的js文件名
		if (src.indexOf(fileName) !== -1) {
			// 获取js文件名后面的所有参数
			src = src.substring(src.lastIndexOf(fileName + "?")
					+ (fileName.length + 1));
			var array = src.split("&");
			// 将参数一个一个遍历出来
			for ( var j = 0; j < array.length; j++) {
				var finalObj = array[j].split("=");
				resultJson[finalObj[0]] = finalObj[1];
			}
		}
	}
	return resultJson;
};

Array.prototype.contains = function(item) {
	return RegExp("\\b" + item + "\\b").test(this);
};
